{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import time, re\n",
    "import json\n",
    "from bs4 import BeautifulSoup\n",
    "import requests as sys_requests\n",
    "import pandas as pd\n",
    "from selenium import webdriver"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "driver=webdriver.Firefox(executable_path='geckodriver.exe')  \n",
    "driver.implicitly_wait(3)  \n",
    "response=driver.get(url)  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 爬取公司信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<table id=\"comInfo1\" width=\"100%\">\n",
       "<tr>\n",
       "<td class=\"ct\">公司名称：</td>\n",
       "<td class=\"ccl\" colspan=\"3\">上海浦东发展银行股份有限公司</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td class=\"ct\">公司英文名称：</td>\n",
       "<td class=\"ccl\" colspan=\"3\">Shanghai Pudong Development Bank Co.,Ltd.</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td class=\"ct\">上市市场：</td>\n",
       "<td class=\"cc\">上海证券交易所</td>\n",
       "<td class=\"ct\">上市日期：</td>\n",
       "<td class=\"cc\"> <a href=\"/corp/view/vCI_CorpInfoLink.php?stockid=600000&amp;InMarketDate=199911\" target=\"_blank\">1999-11-10</a></td> </tr>\n",
       "<tr>\n",
       "<td class=\"ct\">发行价格：</td>\n",
       "<td class=\"cc\">10.00</td>\n",
       "<td class=\"ct\">主承销商：</td>\n",
       "<td class=\"cc\"> <a href=\"/corp/view/vCI_CorpInfoLink.php?stockid=600000&amp;Dealer=海通证券有限公司\" target=\"_blank\">海通证券有限公司</a> \n",
       "\t\t\t\t</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td class=\"ct\">成立日期：</td>\n",
       "<td class=\"cc\"><a href=\"/corp/view/vCI_CorpInfoLink.php?stockid=600000&amp;EstablishDate=199210\" target=\"_blank\">1992-10-19</a></td>\n",
       "<td class=\"ct\">注册资本：</td>\n",
       "<td class=\"cc\">2935210万元</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td class=\"ct\">机构类型：</td>\n",
       "<td class=\"cc\">股份制商业银行</td>\n",
       "<td class=\"ct\">组织形式：</td>\n",
       "<td class=\"cc\"></td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td class=\"ct\">董事会秘书：</td>\n",
       "<td class=\"cc\">谢伟</td>\n",
       "<td class=\"ct\">公司电话：</td>\n",
       "<td class=\"cc\">021-63611226,021-61618888</td></tr>\n",
       "<tr>\n",
       "<tr>\n",
       "<td class=\"ct\">董秘电话：</td>\n",
       "<td class=\"cc\">021-63611226</td>\n",
       "<td class=\"ct\">公司传真：</td>\n",
       "<td class=\"cc\">021-63230807</td></tr>\n",
       "<tr>\n",
       "<tr>\n",
       "<td class=\"ct\">董秘传真：</td>\n",
       "<td class=\"cc\">021-63230807</td>\n",
       "<td class=\"ct\">公司电子邮箱：</td>\n",
       "<td class=\"cc\"> <a href=\"mailto:bdo@spdb.com.cn\" target=\"_blank\">bdo@spdb.com.cn</a> \n",
       "\t\t\t\t</td></tr>\n",
       "<tr>\n",
       "<tr>\n",
       "<td class=\"ct\">董秘电子邮箱：</td>\n",
       "<td class=\"cc\">xiew2@spdb.com.cn</td>\n",
       "<td class=\"ct\">公司网址：</td>\n",
       "<td class=\"cc\"><a href=\"http://www.spdb.com.cn\" target=\"_blank\">http://www.spdb.com.cn </a></td></tr>\n",
       "<tr>\n",
       "<tr>\n",
       "<td class=\"ct\">邮政编码：</td>\n",
       "<td class=\"cc\">200002</td>\n",
       "<td class=\"ct\">信息披露网址：</td>\n",
       "<td class=\"cc\"><a href=\"www.sse.com.cn\" target=\"_blank\"></a></td></tr>\n",
       "<tr>\n",
       "<tr>\n",
       "<td class=\"ct\">证券简称更名历史：</td>\n",
       "<td class=\"ccl\" colspan=\"3\">G浦发 浦发银行 </td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td class=\"ct\">注册地址：</td>\n",
       "<td class=\"ccl\" colspan=\"3\">上海市中山东一路12号</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td class=\"ct\">办公地址：</td>\n",
       "<td class=\"ccl\" colspan=\"3\">上海市中山东一路12号,香港中环夏悫道12号美国银行中心15及24楼</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td class=\"ct\">公司简介：</td>\n",
       "<td class=\"ccl\" colspan=\"3\">    上海浦东发展银行股份有限公司为1992年8月28日经中国人民银行总行以银复(1992)350号文批准设立的股份制商业银行,1992年10月19日由上海市工商行政管理局颁发法人营业执照,1993年1月9日正式开业。上海浦东发展银行股份有限公司于1999年11月10日上市交易。</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td class=\"ct\">经营范围：</td>\n",
       "<td class=\"ccl\" colspan=\"3\">吸收公众存款;发放短期、中期和长期贷款;办理结算;办理票据贴现;发行金融债券;代理发行、代理兑付、承销政府、买卖政府债券;同业拆借;提供信用证服务及担保;代理收付款项及代理保险业务;提供保管箱服务;外汇存款、外汇贷款、外汇汇款、外币兑换;国际结算;同业外汇拆借;外汇票据的承兑和贴现;外汇借款、外汇担保;结汇、售汇;买卖和代理买卖股票以外的外币有价证券;自营和代客外汇买卖;从事银行卡业务;资信调查、咨询、见证业务;离岸银行业务;经批准的其它业务。</td>\n",
       "</tr>\n",
       "</tr></tr></tr></tr></tr></table>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "url = \"http://vip.stock.finance.sina.com.cn/corp/go.php/vCI_CorpInfo/stockid/600000.phtml\"\n",
    "response = sys_requests.get(url=url).content.decode('gbk')\n",
    "soup = BeautifulSoup(response, \"html.parser\")\n",
    "soup.find(id=\"comInfo1\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "http://finance.sina.com.cn/stock/sl/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "8300\n"
     ]
    }
   ],
   "source": [
    "print(info[26])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {},
   "outputs": [],
   "source": [
    "stock={\n",
    "    \"name\":info[0],\n",
    "    \"open\":info[1],\n",
    "    \"close\":info[2],\n",
    "    \"currrent\":info[3],\n",
    "    \"high\":info[4],\n",
    "    \"low\":info[5],\n",
    "    \"a1_v\":info[6],\n",
    "    \"b1_v\":info[7],\n",
    "    \"v_num\":info[8],\n",
    "    \"money\":info[9],\n",
    "    \"a1_v\":info[10],\n",
    "    \"a1_p\":info[11],\n",
    "    \"a2_v\":info[12],\n",
    "    \"a2_p\":info[13],\n",
    "    \"a3_v\":info[14],\n",
    "    \"a3_p\":info[15],\n",
    "    \"a4_v\":info[16],\n",
    "    \"a4_p\":info[17],\n",
    "    \"a5_v\":info[18],\n",
    "    \"a5_p\":info[19],\n",
    "    \"b1_v\":info[20],\n",
    "    \"b1_p\":info[21],\n",
    "    \"b2_v\":info[22],\n",
    "    \"b3_p\":info[23],\n",
    "    \"b4_v\":info[24],\n",
    "    \"b4_p\":info[25],\n",
    "    \"b4_v\":info[26],\n",
    "    \"b4_p\":info[27],\n",
    "    \"b5_p\":info[28],\n",
    "    \"b5_p\":info[29],\n",
    "    \"date\":info[30],\n",
    "    \"time\":info[31],\n",
    "    \"systime\":datetime.datetime.now().strftime('%Y-%m-%d'),\n",
    "\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'name': '晶方科技',\n",
       " 'open': '21.750',\n",
       " 'close': '21.690',\n",
       " 'currrent': '23.030',\n",
       " 'high': '23.360',\n",
       " 'low': '21.750',\n",
       " 'a1_v': '1300',\n",
       " 'b1_v': '23216',\n",
       " 'v_num': '11165943',\n",
       " 'money': '255386666.000',\n",
       " 'a1_p': '23.020',\n",
       " 'a2_v': '3200',\n",
       " 'a2_p': '23.000',\n",
       " 'a3_v': '1200',\n",
       " 'a3_p': '22.980',\n",
       " 'a4_v': '2400',\n",
       " 'a4_p': '22.950',\n",
       " 'a5_v': '10800',\n",
       " 'a5_p': '22.940',\n",
       " 'b1_p': '23.030',\n",
       " 'b2_v': '42100',\n",
       " 'b3_p': '23.040',\n",
       " 'b4_v': '8300',\n",
       " 'b4_p': '23.060',\n",
       " 'b5_p': '23.070',\n",
       " 'date': '2019-10-28',\n",
       " 'time': '15:00:00',\n",
       " 'systime': '2019-10-28'}"
      ]
     },
     "execution_count": 99,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  },
  "pycharm": {
   "stem_cell": {
    "cell_type": "raw",
    "source": [],
    "metadata": {
     "collapsed": false
    }
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}